import { Component, inject, OnInit } from '@angular/core';
import { CommentService, CommentType } from "../../../services/common/Comments";
import { StudyShareModule } from "../../StudyShareModule";
import { Router } from "@angular/router";
import { HttpClient } from "@angular/common/http";
import { httpInterceptorProviders } from "../../../interceptor";

@Component({
  selector: 'app-comment-list',
  standalone: true,
  imports: [StudyShareModule],
  templateUrl: './comment-list.component.html',
  styleUrls: [],
  // providers:[httpInterceptorProviders]
})
export class CommentListComponent implements OnInit {

  commentList: CommentType[] = [];
  http: HttpClient = inject(HttpClient);
  className: string[] = ['danger', 'warning', 'success', 'info']

  ngOnInit(): void {
    this.commentService.getComments2().subscribe(comments => {
      this.commentList = comments;
      console.log(this.commentList)
    })
  }

  constructor(private commentService: CommentService, private router: Router) {

  }


  doGo(id: number): void {
    // this.router.navigate(['/study/comment-detail2', {id}]).then(r => console.log(r));

    this.router.navigateByUrl('/study/comment-detail2?id=' + id).then(r => console.log(r));
  }

  doGo2(id: number): void {
    // this.router.navigate(['/study/comment-detail', id]).then(r => console.log(r));
    this.router.navigateByUrl('/study/comment-detail/' + id)
  }


  add() {
    this.router.navigateByUrl("/study/comment-add").then(r => { console.log(r) })
  }

  add2() {
    this.http.get('https://codeleading.com/article/93423191169/').subscribe(r => { console.log(r) })
  }
}
